package com.blensmile.testvido.utils;

import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

import java.util.ArrayList;
import java.util.List;

public class PermissionHelper {

    public boolean checkPermission(Activity context, String[] ps, int requestCode){
        if(Build.VERSION.SDK_INT>=23 && context!=null && ps != null){
            try{
                List<String> list = new ArrayList<String>();
                for(String item : ps){
                    if(PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(context,item))
                        list.add(item);
                }
                if(list.size()>0){
                    String[] a = new String[list.size()];
                    ActivityCompat.requestPermissions(context,list.toArray(a),requestCode);
                    return false;
                }
            }catch (Exception e){
                e.printStackTrace();
                return false;
            }
        }
        return true;
    }


}
